//
//  CJEmoticonPopoView.swift
//  SinaWeibo
//
//  Created by 程建 on 16/10/11.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import pop

class CJEmoticonPopoView: UIView {

    @IBOutlet weak var emoticonButton: CJEmoticonButtton!
   
    var lastEmoticon: CJEmoticon?
    
    //添加一个类方法,加载该视图
    class func loadPopoView()->CJEmoticonPopoView {
        
        let nib = UINib(nibName: "CJEmoticonPopoView", bundle: nil)
        
        return nib.instantiate(withOwner: nil, options: nil).last as! CJEmoticonPopoView
        
    }
    
    func show() {
        
        if let em = lastEmoticon {
        
            if em.chs == emoticonButton.emoticon?.chs {
                //是同一个表情图片就返回
                return
            }
            if em.code == emoticonButton.emoticon?.code {
                //是同一个emoji表情
                return
            }
        }
        
        
        //实例化动画者
        let anim = POPSpringAnimation(propertyNamed: kPOPLayerPositionY)!
        
        anim.fromValue = 40
        anim.toValue = 25
        
        anim.springBounciness = 20
        anim.springSpeed = 20
        
        emoticonButton.pop_add(anim, forKey: nil)
        //将上一次的表情模型记录下来
        lastEmoticon = emoticonButton.emoticon
        
    }
    
}
